package com.google.code.p.restrpc.client;

import java.lang.reflect.Method;

import com.google.code.p.restrpc.RpcContext;
import com.google.code.p.restrpc.RpcOptions;
import com.google.code.p.restrpc.TransferFormat;
import com.google.code.p.restrpc.UrlParser;
import com.google.code.p.restrpc.client.cluster.FailureRecovery;
import com.google.code.p.restrpc.client.loadbalance.LoadBalance;

/**
 * @author dz
 */
public class DefaultRpcContext implements RpcContext {
    
    private RpcProxy rpcProxy;
    
    private RpcOptions rpcOptions;
    
    private String serviceName;
    
    private Class targetClass;
    
    private Method targetMethod;
    
    private Object[] parameters;
    
    public DefaultRpcContext(RpcProxy rpcProxy) {
        this(rpcProxy, new DefaultRpcOptions());
    }
    
    public DefaultRpcContext(RpcProxy rpcProxy, RpcOptions rpcOptions) {
        this.rpcProxy = rpcProxy;
        this.rpcOptions = rpcOptions;
    }
    
    public RpcProxy getRpcProxy() {
        return this.rpcProxy;
    }
    
    public String getServiceName() {
        return serviceName;
    }
    
    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }
    
    public String getMethodName() {
        return targetMethod.getName();
    }
    
    public Class getTargetClass() {
        return targetClass;
    }
    
    public void setTargetClass(Class targetClass) {
        this.targetClass = targetClass;
    }
    
    public Method getTargetMethod() {
        return targetMethod;
    }
    
    public void setTargetMethod(Method targetMethod) {
        this.targetMethod = targetMethod;
    }
    
    public Object[] getParameters() {
        return parameters;
    }
    
    public void setParameters(Object[] parameters) {
        this.parameters = parameters;
    }
    
    // *****************delegate*****************
    
    public String getDirectoryServiceUrl() {
        return rpcOptions.getDirectoryServiceUrl();
    }
    
    public FailureRecovery getFailureRecovery() {
        return rpcOptions.getFailureRecovery();
    }
    
    public LoadBalance getLoadBalance() {
        return rpcOptions.getLoadBalance();
    }
    
    public int getNumberOfRetries() {
        return rpcOptions.getNumberOfRetries();
    }
    
    public int getHeartbeat() {
        return rpcOptions.getHeartbeat();
    }
    
    public UrlParser getUrlParser() {
        return rpcOptions.getUrlParser();
    }
    
    public TransferFormat getTransferFormat() {
        return rpcOptions.getTransferFormat();
    }
    
}
